import javaService from '@/Yapi/java/javaHttp'

/**
 * 字典数据管理API
 */

// 多条件分页获取字典数据列表
export function getDictDataByCondition(params) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/dictData/getByCondition`,
    method: 'get',
    params
  })
}

// 通过字典类型获取字典数据
export function getDictDataByType(type) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/dictData/getByType/${type}`,
    method: 'get'
  })
}

// 添加字典数据
export function addDictData(data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/dictData/add`,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: [function(data) {
      let ret = ''
      for (const it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret.slice(0, -1)
    }]
  })
}

// 编辑字典数据
export function editDictData(data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/dictData/edit`,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: [function(data) {
      let ret = ''
      for (const it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret.slice(0, -1)
    }]
  })
}

// 批量删除字典数据
export function deleteDictData(ids) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/dictData/delByIds/${ids}`,
    method: 'delete'
  })
}
